﻿using System;
using System.IO.Pipelines;

namespace JTActiveSafety.Gateway.Internal
{
    internal class TerminalConnection : TerminalProtocol, IRequestProcessor
    {
        private readonly HttpConnectionContext _context;

        public TerminalConnection(HttpConnectionContext context)
        {
            Initialize(context);

            _context = context;
            //_parser = ServiceContext.HttpParser;
            //_keepAliveTicks = ServerOptions.Limits.KeepAliveTimeout.Ticks;
            //_requestHeadersTimeoutTicks = ServerOptions.Limits.RequestHeadersTimeout.Ticks;

            //_http1Output = new Http1OutputProducer(
            //    _context.Transport.Output,
            //    _context.ConnectionId,
            //    _context.ConnectionContext,
            //    _context.MemoryPool,
            //    _context.ServiceContext.Log,
            //    _context.TimeoutControl,
            //    minResponseDataRateFeature: this,
            //    outputAborter: this);

            //Input = _context.Transport.Input;
            //Output = _http1Output;
            //MemoryPool = _context.MemoryPool;
        }

        public void Abort(ConnectionAbortedException ex)
        {
            throw new NotImplementedException();
        }

        public void HandleReadDataRateTimeout()
        {
            throw new NotImplementedException();
        }

        public void HandleRequestHeadersTimeout()
        {
            throw new NotImplementedException();
        }

        public void OnInputOrOutputCompleted()
        {
            throw new NotImplementedException();
        }

        //public Task ProcessRequestsAsync<TContext>(IHttpApplication<TContext> application)
        //{
        //    throw new NotImplementedException();
        //}

        public void StopProcessingNextRequest()
        {
            throw new NotImplementedException();
        }

        public void Tick(DateTimeOffset now)
        {
            throw new NotImplementedException();
        }

        protected override void ApplicationAbort()
        {
            throw new NotImplementedException();
        }

        protected override string CreateRequestId()
        {
            throw new NotImplementedException();
        }

        protected override void OnReset()
        {
            throw new NotImplementedException();
        }

        protected override bool TryParseRequest(ReadResult result, out bool endConnection)
        {
            throw new NotImplementedException();
        }
    }
    //internal partial class Http1Connection : IHttpMinRequestBodyDataRateFeature,
    //                                         IHttpMinResponseDataRateFeature
    //{
    //    MinDataRate IHttpMinRequestBodyDataRateFeature.MinDataRate
    //    {
    //        get => MinRequestBodyDataRate;
    //        set => MinRequestBodyDataRate = value;
    //    }

    //    MinDataRate IHttpMinResponseDataRateFeature.MinDataRate
    //    {
    //        get => MinResponseDataRate;
    //        set => MinResponseDataRate = value;
    //    }
    //}


    /// <summary>
    /// When implemented by a Server allows an <see cref="IHttpApplication{TContext}"/> to pool and reuse
    /// its <typeparamref name="TContext"/> between requests.
    /// </summary>
    /// <typeparam name="TContext">The <see cref="IHttpApplication{TContext}"/> Host context</typeparam>
    public interface IHostContextContainer<TContext> where TContext : notnull
    {
        /// <summary>
        /// Represents the <typeparamref name="TContext"/>  of the host.
        /// </summary>
        TContext HostContext { get; set; }
    }
 
    internal sealed class TerminalConnection<TContext> : TerminalConnection, IHostContextContainer<TContext>
    {
        public TerminalConnection(HttpConnectionContext context) : base(context) { }

        TContext IHostContextContainer<TContext>.HostContext { get; set; }
    }
}